﻿using NewsMine.Storage;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace NewsMine.Storage.Tests
{
    [Serializable]
    public class TestObject
    {
        public string Name { get; set; }
    }
    
    /// <summary>
    ///  
    ///This is a test class for QueueManagerOnFileSystemTest and is intended
    ///to contain all QueueManagerOnFileSystemTest Unit Tests
    ///</summary>
    [TestClass()]
    public class QueueManagerOnFileSystemTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for QueueManagerOnFileSystem Constructor
        ///</summary>
        [TestMethod()]
        public void QueueManagerOnFileSystemConstructorTest()
        {
            QueueManagerOnFileSystem target = new QueueManagerOnFileSystem();

            Assert.IsNotNull(target);
        }

        /// <summary>
        ///A test for ClearQueue
        ///</summary>
        [TestMethod()]
        public void ClearQueueTest()
        {
            QueueManagerOnFileSystem target = new QueueManagerOnFileSystem();
            string name = "testQueue1";
            target.CreateQueue(name);
            var queue = target.GetQueueByName(name);

            queue.Enqueue(new TestObject { Name="surendra"});

            int itemsCount = queue.GetCount();
            Assert.IsTrue(itemsCount > 0);

            target.ClearQueue(name);

            itemsCount = queue.GetCount();

            Assert.IsTrue(itemsCount == 0);

            target.DeleteQueue(name);
            Assert.IsNotNull(queue);
        }

        /// <summary>
        ///A test for CreateQueue
        ///</summary>
        [TestMethod()]
        public void CreateQueueTest()
        {
            QueueManagerOnFileSystem target = new QueueManagerOnFileSystem(); 
            string name = "testQueue1"; 
            target.CreateQueue(name);
            var queue = target.GetQueueByName(name);
            target.DeleteQueue(name);
            Assert.IsNotNull(queue);
        }

        /// <summary>
        ///A test for DeleteQueue
        ///</summary>
        [TestMethod()]
        public void DeleteQueueTest()
        {
            QueueManagerOnFileSystem target = new QueueManagerOnFileSystem();
            string name = "testQueue2ForDelete";
            target.CreateQueue(name);
            var queue = target.GetQueueByName(name);
            target.DeleteQueue(name);
            Assert.IsNotNull(queue);
        }

        /// <summary>
        ///A test for GetQueueByName
        ///</summary>
        [TestMethod()]
        public void GetQueueByNameTest()
        {
            QueueManagerOnFileSystem target = new QueueManagerOnFileSystem();
            string name = "testQueue1ForQueueByNameTest";
            target.CreateQueue(name);
            var queue = target.GetQueueByName(name);
            target.DeleteQueue(name);
            Assert.IsNotNull(queue);
        }

       

        /// <summary>
        ///A test for ListAllQueueNames
        ///</summary>
        [TestMethod()]
        public void ListAllQueueNamesTest()
        {
            QueueManagerOnFileSystem target = new QueueManagerOnFileSystem();

            string test1 = "test1";
            string test2 = "test2";

            target.CreateQueue(test1);
            target.CreateQueue(test2);

            List<string> actual;
            actual = target.ListAllQueueNames();
            Assert.IsTrue(actual != null);
            Assert.IsTrue(actual.Count > 0);

            target.DeleteQueue(test1);
            target.DeleteQueue(test2);

        }

        
    }
}
